home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2011 November
/
CHIP_2011_11.iso
/
Programy
/
Inne
/
Gry
/
Carnage_Contest
/
scripts
/
CC Original
/
tools
/
Sentry.lua
< prev
next >
Wrap
Text File
|
2010-09-16
|
10KB
|
311 lines
--------------------------------------------------------------------------------
-- Weapon Sentry
-- Original Carnage Contest Weapon
-- Script by DC, September 2010, www.UnrealSoftware.de
--------------------------------------------------------------------------------
-- Setup Tables
if cc==nil then cc={} end
cc.sentry={}
cc.sentry.sen={}
cc.sentry.bullet={}
-- Load & Prepare Ressources
cc.sentry.sfx_place=loadsfx("throw.ogg") -- Attack Sound
cc.sentry.sfx_bounce=loadsfx("bounce.wav") -- Bounce
cc.sentry.gfx_wpn=loadgfx("buildings/sentry.bmp") -- Sentry
setmidhandle(cc.sentry.gfx_wpn)
cc.sentry.gfx_gun=loadgfx("buildings/sentry_gun.bmp") -- Gun
cc.sentry.gfx_icon=loadgfx("buildings/sentry_icon.bmp") -- Icon
setmidhandle(cc.sentry.gfx_icon)
cc.sentry.gfx_pro=loadgfx("weapons/shot.bmp") -- Projectile Image
setmidhandle(cc.sentry.gfx_pro)
cc.sentry.sfx_attack=loadsfx("sentry.ogg") -- Attack Sound
--------------------------------------------------------------------------------
-- Weapon: Sentry
--------------------------------------------------------------------------------
cc.sentry.id=addweapon("cc.sentry","Sentry",cc.sentry.gfx_icon,0,2) -- Add Weapon (0 uses, first in round 2)
function cc.sentry.draw() -- Draw
-- HUD Positioning
if weapon_shots==0 then
hudpositioning(pos_build,cc.sentry.gfx_wpn,30,1,1,1)
-- HUD Info
hudinfo("The sentry will point into the same direction as you do!")
end
end
function cc.sentry.attack(attack) -- Attack
if (weapon_shots<=0) and (weapon_position==1) then
-- No more weapon switching!
useweapon(0)
playsound(cc.sentry.sfx_place)
weapon_shots=weapon_shots+1
createobject(cc.sentry.sen.id,weapon_x,weapon_y)
-- End Turn
endturn()
end
end
--------------------------------------------------------------------------------
-- Projectile: Bullet
--------------------------------------------------------------------------------
cc.sentry.bullet.id=addprojectile("cc.sentry.bullet") -- Add Projectile
function cc.sentry.bullet.draw(id) -- Draw
-- Setup draw mode
setblend(blend_light)
setalpha(1)
setcolor(255,255,0)
setscale(1,1)
-- Calculate projectile rotation
setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
-- Draw projectile
drawimage(cc.sentry.gfx_pro,projectiles[id].x,projectiles[id].y)
-- Draw Arrow if out of Screen
outofscreenarrow(projectiles[id].x,projectiles[id].y)
end
function cc.sentry.bullet.update(id) -- Update
-- Wind + Gravity influence on speed
projectiles[id].sx=projectiles[id].sx+getwind()*0.02
projectiles[id].sy=projectiles[id].sy+getgravity()*0.75
-- Move
cc.sentry.bullet.move(id)
end
function cc.sentry.bullet.move(id)
rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
-- Move (in substep loop for optimal collision precision)
msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
msubx=projectiles[id].sx/msubt
msuby=projectiles[id].sy/msubt
for i=1,msubt,1 do
projectiles[id].x=projectiles[id].x+msubx
projectiles[id].y=projectiles[id].y+msuby
-- Collision
if collision(col3x3,projectiles[id].x+math.sin(math.rad(rot))*20,projectiles[id].y-math.cos(math.rad(rot))*20,1,1,1,-1,projectiles[id].ignore)==1 then
-- Cause damage
if playercollision()~=0 then
playerpush(playercollision(),projectiles[id].sx/10.0,projectiles[id].sy/10.0)
playerdamage(playercollision(),5)
blood(projectiles[id].x+math.sin(math.rad(rot))*20,projectiles[id].y-math.cos(math.rad(rot))*20)
elseif objectcollision()>0 then
objectdamage(objectcollision(),5)
end
-- Destroy terrain
for j=20,22,1 do
terraincircle(projectiles[id].x+math.sin(math.rad(rot))*j,projectiles[id].y-math.cos(math.rad(rot))*j,3,0x00000000)
end
-- Effects
playsound(sfx_ricochet1)
particle(p_smoke,projectiles[id].x+math.sin(math.rad(rot))*21,projectiles[id].y-math.cos(math.rad(rot))*21)
particlefadealpha(0.006)
particle(p_muzzle,projectiles[id].x+math.sin(math.rad(rot))*21,projectiles[id].y-math.cos(math.rad(rot))*21)
-- Free projectile
freeprojectile(id)
return 1
end
-- Water
if (projectiles[id].y)>getwatery()+5 then
-- Effects
particle(p_waterhit,projectiles[id].x,projectiles[id].y)
if math.random(1,2)==1 then
playsound(sfx_hitwater2)
else
playsound(sfx_hitwater3)
end
-- Free projectile
freeprojectile(id)
return 1
end
end
end
--------------------------------------------------------------------------------
-- Object: Sentry
--------------------------------------------------------------------------------
cc.sentry.sen.id=addobject("cc.sentry.sen",cc.sentry.gfx_wpn) -- Add Object
function cc.sentry.sen.setup(id,parameter)
if objects==nil then objects={} end
objects[id]={}
objects[id].sy=0
objects[id].timer=0
objects[id].burst=0
objects[id].burstrow=0
objects[id].health=30
objects[id].dir=getplayerdirection(0)
objects[id].owner=playercurrent()
end
function cc.sentry.sen.draw(id,x,y)
-- Setup draw mode
setblend(blend_alpha)
setalpha(1)
setcolor(255,255,255)
setscale(1,1)
setrotation(0)
-- Draw Sentry
drawimage(cc.sentry.gfx_wpn,x,y)
-- Draw Gun
setscale(objects[id].dir,1)
if objects[id].dir==1 then
drawimage(cc.sentry.gfx_gun,x+4,y-6)
else
drawimage(cc.sentry.gfx_gun,x-3,y-6)
end
end
function cc.sentry.sen.update(id,x,y)
-- Gravity influence on speed
objects[id].sy=objects[id].sy+getgravity()
-- Move (in substep loop for optimal collision precision)
msubt=math.ceil(math.abs(objects[id].sy)/15)
msuby=objects[id].sy/msubt
for i=1,msubt,1 do
y=y+msuby
-- Collision
if collision(cc.sentry.gfx_wpn,x,y,1,1,1,-1,id)==1 then
if (math.abs(objects[id].sy)>0.5) then playsound(cc.sentry.sfx_bounce) end
y=y-msuby
objects[id].sy=-objects[id].sy*0.3
msuby=-msuby*0.3
end
-- Water
if y>getwatery()+5 then
-- Effects
particle(p_waterhit,x,y)
playsound(sfx_hitwater1)
-- Remove
removeobject(id)
return
end
end
objectposition(id,x,y)
-- Scan for Enemies / Shoot
if objects[id].burst==0 then
objects[id].timer=objects[id].timer+1
if objects[id].timer>=50 then
-- Scan Blink
particle(p_muzzle,x,y-6)
local team=getplayerteam(objects[id].owner)
if team==0 then particlecolor(0,255,0) end
if team==1 then particlecolor(255,255,0) end
if team==2 then particlecolor(255,0,0) end
if team==3 then particlecolor(80,200,255) end
if team==4 then particlecolor(180,60,255) end
if team==5 then particlecolor(255,180,0) end
if team==6 then particlecolor(0,180,0) end
if team==7 then particlecolor(50,100,255) end
particlesize(0.25,0.25)
particlealpha(1.0)
particlefadealpha(0.05)
-- Scan all players
objects[id].timer=0
local players=playertable(0,0)
local ownally=getplayeralliance(objects[id].owner)
for i=1,#players do
-- Enemy?
if getplayeralliance(players[i])~=ownally then
-- In Range?
if math.abs(getplayery(players[i])-y)<30 then
if math.abs(getplayerx(players[i])-x)<400 then
-- Righ Direction?
if (objects[id].dir==1 and getplayerx(players[i])>x) or (objects[id].dir==-1 and getplayerx(players[i])<x) then
-- Something blocking?
local dist=(math.abs(getplayerx(players[i])-x))-8
local tx=x+objects[id].dir*14
local ty=y-3
local ok=1
for offsetx=1,dist,5 do
if collision(col3x3,tx+offsetx*objects[id].dir,ty,1,1,1,players[i])==1 then
ok=0; break;
end
end
if ok==1 then
-- Ready to fire!
objects[id].burst=1
objects[id].burstrow=objects[id].burstrow+1
if objects[id].burstrow>=6 then
-- Overheating! (don't shoot for 10 seconds after 5 bursts)
objects[id].burst=0
objects[id].timer=(-50)*10
playsound(sfx_steam)
particle(p_smoke,x,y-6); particle(p_smoke,x,y-10); particle(p_smoke,x-3,y-8); particle(p_smoke,x+3,y-8)
particle(p_spark,x,y-9); particle(p_spark,x-4,y-9); particle(p_spark,x+4,y-9)
end
end
end
end
end
end
end
if objects[id].burst==0 then
objects[id].burstrow=0
end
end
else
if getframe()%5==0 then
objects[id].burst=objects[id].burst+1
if objects[id].burst>10 then
-- Burst Done!
objects[id].burst=0
objects[id].timer=0
else
-- Shoot!
playsound(cc.sentry.sfx_attack)
local pid=createprojectile(cc.sentry.bullet.id)
projectiles[pid]={}
-- Ignore Object
projectiles[pid].ignore=id
-- Set initial position of projectile
projectiles[pid].x=x+objects[id].dir*14
projectiles[pid].y=y-3
-- Set speed of projectile
math.randomseed(objects[id].burst*12345)
offset=-6.0+math.random()*12.0
projectiles[pid].sx=math.sin(math.rad(90*objects[id].dir+offset))*15.0
projectiles[pid].sy=-math.cos(math.rad(90*objects[id].dir+offset))*15.0
-- Initial movement
projectiles[pid].x=projectiles[pid].x-objects[id].dir*20
cc.sentry.bullet.move(pid)
-- Effects
particle(p_muzzle,projectiles[pid].x,projectiles[pid].y)
particle(p_smoke,projectiles[pid].x,projectiles[pid].y)
particlespeed(-0.2+math.random()*0.4+getwind()*10.0,-1.0+math.random()*0.6)
particlefadealpha(0.005)
particle(p_bullet,x,y-7)
end
end
return 1
end
end
function cc.sentry.sen.damage(id,damage)
if objects[id].health>0 then
objects[id].health=objects[id].health-damage
if objects[id].health<=0 then
local x=getobjectx(id)
local y=getobjecty(id)
-- Destroy terrain
terrainexplosion(x,y,35,1)
-- Crater
grey=math.random(0,40)
if math.random(0,1)==1 then
terrainalphaimage(gfx_crater100,x,y,math.random(6,9)*0.1,grey,grey,grey)
else
terrainalphaimage(gfx_crater125,x,y,math.random(6,9)*0.1,grey,grey,grey)
end
-- Remove
removeobject(id)
-- Cause damage
arealdamage(x,y,65,35)
end
end
end